<?php
/**
 * Created by PhpStorm.
 * User: xuezhileikaku
 * Email:chengyingbo88@163.com
 * Date: 2024/8/23
 * Time: 下午6:27
 */
require_once __DIR__ . '/../vendor/autoload.php';

use App\App;
use App\Container\DiContainer;
use App\Logger\LoggerFactory;
use App\Event\ListenerProvider;
use App\Event\EventDispatcher;
use App\Routing\Router;
use App\Config\Config;
use App\Service\ServiceRegistry;
use Psr\Log\LoggerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;

// 创建容器
$container = new DiContainer();

// 加载配置
$config = new Config(require __DIR__ . '/../config/config.php');
$container->set(Config::class, $config);

// 设置日志记录器
$logger = LoggerFactory::createLogger();
$container->set(LoggerInterface::class, $logger);

// 设置服务注册表
$serviceRegistry = new ServiceRegistry();
$container->set(ServiceRegistry::class, $serviceRegistry);

// 设置事件调度器
$listenerProvider = new ListenerProvider();
$eventDispatcher = new EventDispatcher($listenerProvider);
$container->set(EventDispatcherInterface::class, $eventDispatcher);
$container->set(ListenerProvider::class, $listenerProvider);

// 创建路由器并注册路由
$router = new Router();
$router->addRoute('GET', '/hello', function ($request) {
    return new \GuzzleHttp\Psr7\Response(200, [], 'Hello, World!');
});
$container->set(Router::class, $router);

// 创建应用程序实例并运行
$app = new App($container, $logger, $eventDispatcher, $router);
$app->run();


